package com.ksd.modules.rbac.api.controller;

import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.modules.rbac.api.entity.SysApis;
import com.ksd.modules.rbac.api.service.ISysRoleApisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色权限表 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-13
 */
@RestController
public class SysRoleApisController  extends BaseController {


    @Autowired
    private ISysRoleApisService sysRoleApisService;

    /**
     * 查询菜单的信息
     * @return
     */
    @PostMapping("/sys/roleapis/apis")
    public R<List<SysApis>> findApis(){
        List<SysApis> menuList = sysRoleApisService.findApis();
        return R.data(menuList);
    }

    /**
     * 查询角色授权的菜单信息
     * @return
     */
    @PostMapping("/sys/roleapis/roleapis/{roleId}")
    public R<List<SysApis>> findRolesApis(@PathVariable("roleId") Long roleId){
        List<SysApis> menuList = sysRoleApisService.findRolesApis(roleId);
        return R.data(menuList);
    }

    /**
     * 授权信息
     * @return
     */
    @PostMapping("/sys/roleapis/saveRoleApiss")
    public R<Boolean> saveRoleApiss(@RequestParam("roleId") Long roleId, @RequestParam("apiIds") String apiIds){
        return R.data(sysRoleApisService.saveRoleApiss(roleId,apiIds));
    }
}
